using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace PruebaVelocidadTCPInterno
{
    class Program
    {

        static TcpListener tl = new TcpListener (
            IPAddress.Parse("127.0.0.1"),
            4097
        );

        static void Main (string[] args)
        {
            tl.Start();
            TcpClient tc = tl.AcceptTcpClient();
            byte [] buffer = new byte [8192];
            int acumMega = 0;
            const int _100MEGA = 100 * 1024 * 1024;

            int c = 0;

            using (NetworkStream ns = tc.GetStream())
            {
                int start = Environment.TickCount;

                for (; ; )
                {
                    int leidos = ns.Read(buffer, 0, buffer.Length);
                    acumMega += leidos;

                    if (acumMega >= _100MEGA) {
                        ++c;
                        Console.WriteLine ("100 megas leidos {0}, {1} milis", c, Environment.TickCount - start);
                        acumMega -= _100MEGA;

                        start = Environment.TickCount;
                    }
                }
            }
        }
    }
}
